import java.util.GregorianCalendar;
import java.util.HashMap;

public class FinalExams {
	
	public FinalExams() {}
	
	private HashMap<Student, HashMap<GregorianCalendar, FinalExam>> graduates;
	private HashMap<GregorianCalendar, FinalExam> exams;
	private HashMap<GregorianCalendar, FinalExam>finalExams;
	
	public void addExam(Course course, int maxPoints, GregorianCalendar date) {
		FinalExam exam = new FinalExam(maxPoints, date, course.getProfessor());
		exams.put(exam.getDate(), exam);
	}
	
	public void addExam(FinalExam exam) {
		exams.put(exam.getDate(), exam);
	}
	
	public void enrollExam(Student student, FinalExam exam) {
		if (!graduates.containsKey(student)) {
			graduates.put(student, new HashMap<GregorianCalendar, FinalExam>());
		}
		finalExams = graduates.get(student);
		finalExams.put(exam.getDate(), exam);
	}
	
	public void addAbsolvedExam(Student student, FinalExam exam, int achievedPoints, Mark mark) {
		if (graduates.containsKey(student)) {
			finalExams = graduates.get(student);
			if(finalExams.containsKey(exam.getDate())) {
				FinalExam currentExam = (FinalExam)finalExams.get(exam.getDate());
				currentExam.setPoints(currentExam.getPoints().getMaxPoints(), achievedPoints);
				currentExam.setMark(mark);
			}
		}
	}
	
	public void addAbsolvedExam(Student student, FinalExam exam, int achievedPoints, int mark) {
		if (graduates.containsKey(student)) {
			finalExams = graduates.get(student);
			if(finalExams.containsKey(exam.getDate())) {
				FinalExam currentExam = (FinalExam)finalExams.get(exam.getDate());
				currentExam.setPoints(currentExam.getPoints().getMaxPoints(), achievedPoints);
				currentExam.setMark(mark);
			}
		}
	}
	
	public int getExamAttempts(Student student) {
		return graduates.get(student).size();
	}
	
	public HashMap<Student, HashMap<GregorianCalendar, FinalExam>> getGraduates() {
		return graduates;
	}
}